convert v900 to dynamic Format class. (#1227)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Sat, 18 Nov 2023 21:08:26 +0000 (14:08 -0700)
committerGitHub <noreply@github.com>
Sat, 18 Nov 2023 21:08:26 +0000 (14:08 -0700)
CMakeLists.txt
v900.cc
v900.h [new file with mode: 0644]
vecs.cc

index 9e4a6ee5e194823c9c81d3d614ff30eb0b4536b9..17c70b6ed6f36f80e83c7b479b5d2d438311f10c 100644 (file)
@@ -240,6 +240,7 @@ set(HEADERS
   tpo.h
   unicsv.h
   units.h
+  v900.h
   vcf.h
   vecs.h
   xcsv.h
diff --git a/v900.cc b/v900.cc
index 632195221a068739a7e9ca4213f908d88de9a8bf..4b8fb942e95e6fd2b84a187b59d5ea521ace2dd2 100644 (file)
--- a/v900.cc
+++ b/v900.cc
@@ -71,77 +71,25 @@ for a little more info, see structures:
        one_line_advanced_mode, one_line_basic_mode, one_line_common_start.
 ******************************************************************************/
 
-#include "defs.h"
-#include <cassert>
-#include <cstdio>
-#include <cstdlib> // strtod
+#include "v900.h"
 
-/* the start of each record (line) is common to both advanced and basic mode.
-   it will be parsed by a single common code. hence, it will be easier and clearer
-   to have a common structure for it.
- */
-struct one_line_common_start {
-  char index[6];          /* record number */
-  char comma1;            /* ',' */
-  char tag;               /* tag type. T=trackpoint. TODO: more options??? */
-  char comma2;            /* ',' */
-  char date[6];           /* YYMMDD. YY=09 is 2009. */
-  char comma3;            /* ',' */
-  char time[6];           /* HHMMSS */
-  char comma4;            /* ',' */
-  char latitude_num[9];   /* example: "31.768380" */
-  char latitude_NS;       /* 'N' or 'S' */
-  char comma5;            /* ',' */
-  char longitude_num[10]; /* example: "035.209656" */
-  char longitude_EW;      /* 'E' or 'W' */
-  char comma6;            /* ',' */
-  char height[5];         /* Altitude in meters.
-                                 * (not corrected to WGS84 ??) */
-  char comma7;            /* ',' */
-  char speed[4];          /* speed in km/h. no decimal point. */
-  char comma8;            /* ',' */
-  char heading[3];        /* heading in degrees */
-  char comma9;            /* ',' */
-};
-
-/* this structure holds one record (line) in advanced logging mode.
-   advanced mode lines looks like this ('*' means NULL):
-1717**,T,090204,062634,31.765528N,035.207730E,772**,0***,0**,2D,SPS ,2.1**,1.9**,1.0**,*********
-*/
-struct one_line_advanced_mode {
-  one_line_common_start common;
-  char fixmode[2]; /* "2D" or "3D" */
-  char comma10;    /* ',' */
-  char valid[4];   /* "SPS " or "DGPS" */
-  char comma11;    /* ',' */
-  char pdop[5];
-  char comma12;    /* ',' */
-  char hdop[5];
-  char comma13;    /* ',' */
-  char vdop[5];
-  char comma14;    /* ',' */
-  char vox[9];     /* voicetag recorded */
-  char cr;         /* '\r' */
-  char lf;         /* '\n' */
-};
-
-/* this structure holds one record (line) in basic logging mode.
-   basic mode lines looks like this ('*' means NULL):
-1*****,T,090404,063401,31.765931N,035.206969E,821**,0***,0**,*********
-*/
-struct one_line_basic_mode {
-  one_line_common_start common;
-  char vox[9];    /* voicetag recorded */
-  char cr;        /* '\r' */
-  char lf;        /* '\n' */
-};
+#include <cassert>     // for assert
+#include <cstdarg>     // for va_end, va_start
+#include <cstdio>      // for fclose, fgets, fread, vfprintf, stderr, va_list
+#include <cstdlib>     // for strtod
+#include <cstring>     // for strncmp, strcat, strcpy, strstr
 
+#include <QByteArray>  // for QByteArray
+#include <QDate>       // for QDate
+#include <QTime>       // for QTime
+#include <QtCore>      // for qPrintable, UTC
+
+#include "defs.h"
 
-static FILE* fin = nullptr;
 
 /* copied from dg-100.cpp */
-[[gnu::format(printf, 1, 2)]] static void
-v900_log(const char* fmt, ...)
+void
+V900Format::v900_log(const char* fmt, ...)
 {
   va_list ap;
 
@@ -154,8 +102,8 @@ v900_log(const char* fmt, ...)
   va_end(ap);
 }
 
-static void
-v900_rd_init(const QString& fname)
+void
+V900Format::rd_init(const QString& fname)
 {
   v900_log("%s(%s)\n",__func__,qPrintable(fname));
   /* note: file is opened in binary mode, since lines end with \r\n, and in windows text mode
@@ -168,8 +116,8 @@ v900_rd_init(const QString& fname)
   }
 }
 
-static void
-v900_rd_deinit()
+void
+V900Format::rd_deinit()
 {
   v900_log("%s\n",__func__);
   if (fin) {
@@ -178,8 +126,8 @@ v900_rd_deinit()
 }
 
 /* copied from dg-100.c - slight (incompatible) modification to how the date parameter is used */
-static QDateTime
-bintime2utc(int date, int time) {
+QDateTime
+V900Format::bintime2utc(int date, int time) {
   int secs = time % 100;
   time /= 100;
   int mins = time % 100;
@@ -198,8 +146,8 @@ bintime2utc(int date, int time) {
   return QDateTime(dt, tm, Qt::UTC);
 }
 
-static void
-v900_read()
+void
+V900Format::read()
 {
   /* use line buffer large enough to hold either basic or advanced mode lines. */
   union {
@@ -361,19 +309,3 @@ v900_read()
     }
   }
 }
-
-/* Could be  US-ASCII, since we only read "0-9,A-Z\n\r" */
-
-ff_vecs_t v900_vecs = {
-  ff_type_file,
-  {ff_cap_read, ff_cap_read, ff_cap_none}, /* Read only format. May only read trackpoints and waypoints. */
-  v900_rd_init,
-  nullptr,          /* wr_init */
-  v900_rd_deinit,
-  nullptr,          /* wr_deinit */
-  v900_read,
-  nullptr,          /* write */
-  nullptr,
-  nullptr,          /* args */
-  {nullptr,nullptr,nullptr,nullptr,nullptr,nullptr}
-};
diff --git a/v900.h b/v900.h
new file mode 100644 (file)
index 0000000..5a2b578
--- /dev/null
+++ b/v900.h
@@ -0,0 +1,135 @@
+/*
+       Support for Columbus/Visiontac V900 csv format
+        This format pads fields with NULL up to a fixed per field length.
+        Because of that, and because xcsv does not allows a regex as a field delimiter,
+        a special c module is required.
+
+       Copyright (C) 2009 Tal Benavidor
+
+       This program is free software; you can redistribute it and/or modify
+       it under the terms of the GNU General Public License as published by
+       the Free Software Foundation; either version 2 of the License, or
+       (at your option) any later version.
+
+       This program is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with this program; if not, write to the Free Software
+       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+ */
+#ifndef V900_H_INCLUDED_
+#define V900_H_INCLUDED_
+
+#include <cstdio>     // for FILE
+
+#include <QDateTime>  // for QDateTime
+#include <QString>    // for QString
+#include <QVector>    // for QVector
+
+#include "defs.h"     // for ff_cap, ff_cap_read, ff_cap_none, arglist_t, ff_type, ff_type_file
+#include "format.h"   // for Format
+
+
+class V900Format : public Format
+{
+public:
+  using Format::Format;
+
+  QVector<arglist_t>* get_args() override
+  {
+    return nullptr;
+  }
+
+  ff_type get_type() const override
+  {
+    return ff_type_file;
+  }
+
+  QVector<ff_cap> get_cap() const override
+  {
+    /* Read only format. May only read trackpoints and waypoints. */
+    return {ff_cap_read, ff_cap_read, ff_cap_none};
+  }
+
+  void rd_init(const QString& fname) override;
+  void read() override;
+  void rd_deinit() override;
+
+private:
+  /* Types */
+
+  /* the start of each record (line) is common to both advanced and basic mode.
+     it will be parsed by a single common code. hence, it will be easier and clearer
+     to have a common structure for it.
+   */
+  struct one_line_common_start {
+    char index[6];          /* record number */
+    char comma1;            /* ',' */
+    char tag;               /* tag type. T=trackpoint. TODO: more options??? */
+    char comma2;            /* ',' */
+    char date[6];           /* YYMMDD. YY=09 is 2009. */
+    char comma3;            /* ',' */
+    char time[6];           /* HHMMSS */
+    char comma4;            /* ',' */
+    char latitude_num[9];   /* example: "31.768380" */
+    char latitude_NS;       /* 'N' or 'S' */
+    char comma5;            /* ',' */
+    char longitude_num[10]; /* example: "035.209656" */
+    char longitude_EW;      /* 'E' or 'W' */
+    char comma6;            /* ',' */
+    char height[5];         /* Altitude in meters.
+                                 * (not corrected to WGS84 ??) */
+    char comma7;            /* ',' */
+    char speed[4];          /* speed in km/h. no decimal point. */
+    char comma8;            /* ',' */
+    char heading[3];        /* heading in degrees */
+    char comma9;            /* ',' */
+  };
+
+  /* this structure holds one record (line) in advanced logging mode.
+     advanced mode lines looks like this ('*' means NULL):
+  1717**,T,090204,062634,31.765528N,035.207730E,772**,0***,0**,2D,SPS ,2.1**,1.9**,1.0**,*********
+  */
+  struct one_line_advanced_mode {
+    one_line_common_start common;
+    char fixmode[2]; /* "2D" or "3D" */
+    char comma10;    /* ',' */
+    char valid[4];   /* "SPS " or "DGPS" */
+    char comma11;    /* ',' */
+    char pdop[5];
+    char comma12;    /* ',' */
+    char hdop[5];
+    char comma13;    /* ',' */
+    char vdop[5];
+    char comma14;    /* ',' */
+    char vox[9];     /* voicetag recorded */
+    char cr;         /* '\r' */
+    char lf;         /* '\n' */
+  };
+
+  /* this structure holds one record (line) in basic logging mode.
+     basic mode lines looks like this ('*' means NULL):
+  1*****,T,090404,063401,31.765931N,035.206969E,821**,0***,0**,*********
+  */
+  struct one_line_basic_mode {
+    one_line_common_start common;
+    char vox[9];    /* voicetag recorded */
+    char cr;        /* '\r' */
+    char lf;        /* '\n' */
+  };
+
+  /* Member Functions */
+
+  [[gnu::format(printf, 1, 2)]] static void v900_log(const char* fmt, ...);
+  static QDateTime bintime2utc(int date, int time);
+
+  /* Data Members */
+
+  FILE* fin = nullptr;
+};
+
+#endif // V900_H_INCLUDED_
diff --git a/vecs.cc b/vecs.cc
index 41b5c6943ca25eaa654886fe6c8eeb6ed7c01b62..05c4c7e1985012760cd72c34cb4f163f66fc802c 100644 (file)
--- a/vecs.cc
+++ b/vecs.cc
@@ -71,6 +71,7 @@
 #include "text.h"              // for TextFormat
 #include "tpo.h"               // for Tpo2Format, Tpo3Format
 #include "unicsv.h"            // for UnicsvFormat
+#include "v900.h"              // for V900Format
 #include "vcf.h"               // for VcfFormat
 #include "xcsv.h"              // for XcsvStyle, XcsvFormat
 #include "googletakeout.h"     // for GoogleTakeoutFormat
@@ -92,7 +93,6 @@ extern ff_vecs_t gtm_vecs;
 extern ff_vecs_t garmin_txt_vecs;
 #endif // CSVFMTS_ENABLED
 extern ff_vecs_t ggv_log_vecs;
-extern ff_vecs_t v900_vecs;
 extern ff_vecs_t format_garmin_xt_vecs;
 #endif // MAXIMAL_ENABLED
 
@@ -152,7 +152,6 @@ struct Vecs::Impl {
   ExifFormat exif_fmt;
   HumminbirdFormat humminbird_fmt;
   HumminbirdHTFormat humminbird_ht_fmt;
-  LegacyFormat v900_fmt {v900_vecs};
   SkytraqFormat skytraq_fmt;
   SkytraqfileFormat skytraq_ffmt;
   MinihomerFormat miniHomer_fmt;
@@ -423,11 +422,12 @@ struct Vecs::Impl {
       nullptr,
     },
     {
-      &v900_fmt,
+      nullptr,
       "v900",
       "Columbus/Visiontac V900 files (.csv)",
       nullptr,
       nullptr,
+      &fmtfactory<V900Format>
     },
     {
       &skytraq_fmt,